/** Get Free SMS alerts for your Site's Uptime and Downtime **/ /** Original Script by Amit Agarwal 26/03/2012 **/ /** http://labnol.org/?p=33232 **/ /* Modified by Shunmugha Sundaram to get SMS alerts and to support multiple site monitoring- 31/03/2012 */ /* Instructions at http://techawakening.org/?p=988 */ function isMySiteDown() { var i=3; // Tweak the loop variable if you want to monitor more then 4 sites. for (i=3;i<=6;i++) { // In cell E3 enter the URL of the site you want to monitor var url = SpreadsheetApp.getActiveSheet().getRange("F"+i).getValue(); if(url.length) { var scriptvalue=ScriptProperties.getProperty("status"+ i); if (!scriptvalue) { ScriptProperties.setProperty("status" + i, 200); } var response, error; try { response = UrlFetchApp.fetch(url); } catch(error) { insertData(error, -1, url, i, "Website down"); continue; } var code = response.getResponseCode(); if (code == 200) { { insertData("Up", code, url, i, "Website up"); } } else insertData(response.getContent()[0], code,url, i,"Website down"); //end if } else { //Don't poll it } } } function insertData(error, code, url, i, msg) { if (ScriptProperties.getProperty("status"+i) == code) { return; } var sheet = SpreadsheetApp.getActiveSheet(); var email = sheet.getRange("F5").getValue(); var row = sheet.getLastRow() + 1; var now = new Date().getTime(); sheet.getRange(row,1).setValue(new Date()); sheet.getRange(row,2).setValue(url); sheet.getRange(row,3).setValue(error); sheet.getRange(row,4).setValue(code); ScriptProperties.setProperty("status"+i, code); if(code!=200) CalendarApp.createEvent( url + ' is DOWN' , new Date(now+40000), new Date(now+40000)).addSmsReminder(0); else CalendarApp.createEvent( url + ' is UP' , new Date(now+40000), new Date(now+40000)).addSmsReminder(0); // Uncomment the below line if you want to get Email alerts too. // MailApp.sendEmail(email, msg, error); }